#-Desc: 骨架初始化模块
#-Author: fxl0206

H=localhost

init: #基于脚手架新建一个工具项目脚手架 #n=? //toolName
	@myHome=${pwdDir}/${n} && \
	${scriptsDir}/assertx.sh NotNull n ${n} && \
	${scriptsDir}/ensurex.sh xDir $${myHome}/bin && \
	${scriptsDir}/ensurex.sh xDir $${myHome}/roles && \
	cp -R ${toolHome}/Makefile $${myHome}/ && \
	cp -R ${toolHome}/files $${myHome}/ && \
	cp -R ${toolHome}/roles/test $${myHome}/roles && \
	cp -R ${toolHome}/scripts $${myHome}/ && \
	cp -R ${toolHome}/bin/stx $${myHome}/bin/${n}

update: #更新所有工具集公共文件 #
	@ls ${repxHome} | grep -v "stx" | while read line; \
	do \
	   cp ${toolHome}/Makefile ${repxHome}/$${line}/; \
	   cp ${toolHome}/bin/stx ${repxHome}/$${line}/bin/$${line}; \
	   cp ${toolHome}/scripts/helpx.sh ${repxHome}/$${line}/scripts/helpx.sh; \
	   cp ${toolHome}/scripts/assertx.sh ${repxHome}/$${line}/scripts/assertx.sh; \
	   cp ${toolHome}/scripts/ensurex.sh ${repxHome}/$${line}/scripts/ensurex.sh; \
	done;

commitx: index #提交所有工具集到git #M=? //提交信息
	@${scriptsDir}/assertx.sh NotNull M ${M}
	@ls ${repxHome} | while read line; \
	do \
	   cd ${repxHome}/$${line}/ && git add * && git commit -m "${M}"; \
	done;

pushx: #提交所有工具集到git #
	@ls ${repxHome} | while read line; \
	do \
	   cd ${repxHome}/$${line}/ && git push origin master; \
	done;

pullx: #git pull所有工具集 #
	@ls ${repxHome} | while read line; \
	do \
	   cd ${repxHome}/$${line}/ && git pull; \
	done;
index: #索引
	@echo "">${toolHome}/indexs
	@ls ${repxHome} | while read line; \
	do \
	   echo "repx/$${line}" >>${toolHome}/indexs; \
	done;

listx: #查看可支持的工具 #
	@cat ${toolHome}/indexs	

upgrade: #升级所以模块 #
	@ls ${repxHome}| while read line2; \
	do \
	  basher upgrade repx/$${line2}; \
	done

sparse: #克隆子目录为到当前项目 #P=? /**项目名称*/ 
	@${scriptsDir}/assertx.sh NotNull P ${P}
	@${scriptsDir}/ensurex.sh xDir ${CURDIR}/${P}
	@cd ${CURDIR}/${P} && git init && \
	git remote add -f origin https://gitee.com/repx/${P}.git && \
	git config core.sparsecheckout true && \
	echo "roles/go" >> .git/info/sparse-checkout && \
	git pull origin master